<template>
  <div class="app-container">
    <el-form :inline="true" :model="getRefuelList" class="demo-form-inline">
      <router-link to="/daily_work/refuelingadd">
        <el-button type="success" icon="el-icon-plus">添加</el-button>
      </router-link>
      <el-form-item label="车牌号码">
        <el-input v-model="RefuelQuery.carNo" placeholder="请输入车牌号码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getRefuelList()">查询</el-button>
        <el-button type="primary" @click="refresh()">重置</el-button>
        <el-button type="danger" icon="el-icon-delete" @click="deleteRefuelingByIds()">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="RefuelList"
              style="width: 100%"
              @selection-change="allchecked"
              border>
      <el-table-column label="" width="70" align="center">
        <template slot-scope="scope">
          {{ (current - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column prop="carNo" label="车牌号码" width="100">
      </el-table-column>
      <el-table-column prop="unitName" label="油气站" width="120">
      </el-table-column>
      <el-table-column prop="oilDate" label="加油时间" width="100">
      </el-table-column>
      <el-table-column prop="text" label="油料编号" width="100">
      </el-table-column>
      <el-table-column prop="unitPrice" label="单价" width="100">
      </el-table-column>
      <el-table-column prop="thisGasVolume" label="本次加油量" width="120">
      </el-table-column>
      <el-table-column prop="totalAmount" label="本次加油总价" width="120">
      </el-table-column>
      <el-table-column prop="thisMil" label="本次加油里程" width="120">
      </el-table-column>
      <el-table-column prop="lastMil" label="上次加油里程" width="120">
      </el-table-column>
      <el-table-column prop="lastGasVolume" label="上次加油量" width="120">
      </el-table-column>
      <el-table-column prop="remarks" label="备注" width="100">
      </el-table-column>
      <el-table-column prop="name" label="加油人员" width="100">
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="deleteRefueling(scope.row.id)"
          >删除
          </el-button>

          <router-link :to="'/daily_work/refuelingedit/' + scope.row.id">
            <el-button type="warning" size="mini" icon="el-icon-edit"
            >修改
            </el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      align="center"
      background
      :current-page="this.current"
      :total="total"
      :page-size="limit"
      @current-change="getRefuelList"
      layout="total,prev, pager, next,jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
  import RefuelApi from "@/api/refueling.js"

  export default {
    name: "refuelinglist",
    data() {
      return {
        current: 1,
        limit: 4,
        RefuelQuery: {},
        RefuelList: null,
        total: 0,
        ids: []
      }
    },
    created() {
      this.getRefuelList()
    },
    methods: {
      getRefuelList(current = 1) {
        this.current = current
        RefuelApi.PageByCondition(this.current, this.limit, this.RefuelQuery)
          .then(response => {
            this.RefuelList = response.data.records
            this.total = response.data.total
          })
      },
      refresh() {
        this.RefuelQuery = {}
        this.getRefuelList()
      },
      deleteRefueling(id) {
        this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          RefuelApi.deleteRefuelById(id).then(response => {
            this.getRefuelList()
            this.$message({
              message: "删除成功",
              type: "success",
            })
          })
        })
      },
      allchecked(val) {
        this.ids = []
        for (var i = 0; i < val.length; i++) {
          this.ids.push(val[i].id)
        }
      },
      deleteRefuelingByIds() {
        this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          console.log(this.ids)
          RefuelApi.deleteRefuelById(this.ids).then(response => {
            this.getRefuelList()
            this.$message({
              message: "删除成功",
              type: "success",
            })
          })
        })
      }
    }
  }
</script>

<style scoped>

</style>
